(function(){
    var app = angular.module('skillCalc', ['ngRoute']);

        app.controller('MyController', ['$scope','$location', '$http', function($scope, $location, $http){

            $http.get("data_json.php")
                .success(function(response) { $scope.chars = response; });

           //var obj = JSON.parse(localStorage.getItem('gameStorage'));
            //$scope.chars = obj;
            $scope.site = {
                urlhash: "lookup"
            };

            $scope.change = function(){
                $location.hash($scope.site.urlhash);
            };

            $scope.calc = function(character){
                var effects = [];
                var effectsCondition = [];
                var effectsDuration = [];
                var effectsDurationCondition = [];

                $.each($scope.chars[character].skilltrees, function(key, tree_value){
                    $.each(tree_value.skills, function(key, skill_value){
                        $.each(skill_value.effects, function(key, effect_value) {
                            if(skill_value.condition==null && skill_value.duration==null){
                                effects.push(effect_value);
                            } else if(skill_value.condition!=null && skill_value.duration!=null){
                                effectsDurationCondition.push(effect_value);
                            } else if(skill_value.condition==null && skill_value.duration!=null){
                                effectsDuration.push(effect_value);
                            } else effectsCondition.push(effect_value);
                        });
                    });
                });

                //target in den stat schreiben


                console.log(effects);
            };



            $scope.calculate = function(character){
                console.groupCollapsed('calculate');
                var count = 0;

                var effects = [];
                console.log($scope.chars[character]);
                $.each($scope.chars[character].skilltrees, function(key, tree_value){
                    //console.log(value);

                    $.each(tree_value.skills, function(key, skill_value){
                        //console.log(value);

                        $.each(skill_value.effects, function(key, effect_value){
                            //console.log(value);
                            var cats = effect_value.category.split("_");
                            //console.log(cats);
                            var targets = effect_value.target.split("_");
                            //console.log(targets);

                            if(targets[0]=='player'){
                                console.log(targets);
                            } else if(targets[0]=='pet'){
                                console.log(targets);
                            }

                            if(skill_value.duration==null){
                                effect_value['duration'] = skill_value.duration;
                            }

                            if(skill_value.condition==null){
                                effect_value['condition'] = skill_value.condition;
                            }

                            count++;
                        });
                    });

                });
                console.log('Schleifendurchlaeufe: '+count);
                console.groupEnd();
            };

            console.log($scope.chars);
            //console.log($location);
        }]);

        app.filter('valueRequired', function() {
        return function(input) {
            return input != null ? input : 'none';
        }
    });

        app.config(function($locationProvider){
            $locationProvider.html5Mode(true);
        });

})();